<?php
session_start();
require($_SERVER['DOCUMENT_ROOT'].'/resources/lib/database.php');
require($_SERVER['DOCUMENT_ROOT'].'/resources/lib/functions.php');
require($_SERVER['DOCUMENT_ROOT'].'/resources/lib/class.admin.php');
$admin=new admin();
$id=$_GET['id'];
$content=$admin->getContent($id);
$cid=(string)$content['_id'];
?>
<input type="hidden" id="content_id" name="content_id" value="<?php echo($cid); ?>" />
<table width="100%" cellpadding="4" cellspacing="4">
	<tr valign="top">
    	<td width="62%"><textarea name="content[<?php echo($cid); ?>]" id="content_<?php echo($cid) ?>"></textarea></td>
        <td width="38%">

<div class="qt-tab-wrapper">
<ul class="qt">
<li><a href="#ist1-pages" id="iist1" class="qta selected-tab">Options</a></li>
<li><a href="#ist2-pages" id="iist2" class="qta">Modules</a></li>
</ul>
<div id="ist1-pages" class="qt-content-container selected-tab-container" style="display:block;">

<h2 style="margin-bottom:0.5em;">Tags</h2>
<input type="text" class="form-field" name="content_tags[<?php echo($cid); ?>]" id="content_tags<?php echo($cid); ?>" value="<?php echo(implode(",",$content['tags'])); ?>"/>
<p style="margin-bottom:1em;">(comma separated tags)</p>
<h2 style="margin-bottom:0.5em;">Options</h2>
<table width="100%" cellpadding="4" cellspacing="4">
    <tr>
    	<td width="36%"><strong>Published:</strong></td>
        <td width="64%"> <select name="content_active[<?php echo($cid); ?>]" id="content_active_<?php echo($cid); ?>" class="form-field" style="width:56px;"><?php echo($admin->selectYesNo($content['active'])); ?></select></td>
    </tr>
     <tr>
    	<td width="36%"><strong>Save Content:</strong></td>
        <td width="64%"><select name="content_save[<?php echo($cid); ?>]" id="content_save_<?php echo($cid); ?>" class="form-field" style="width:56px;"><?php echo($admin->selectYesNo(1)); ?></select></td>
    </tr>
</table>
<p>Once happy with your content please press the "Save changes" button at the top.</p>
</div>
<div id="ist2-pages" class="qt-content-container" style="display:none;">
	<ul>
	<?php 
		$modules=$admin->getActiveModules();
		foreach($modules['results'] as $row) {
			echo('<li><h2>'.$row['name'].'</h2><strong>Module Code</strong>: <textarea class="form-field" style="width:100%;height:20px;">[module]{"id":"'.(string)$row['_id'].'"}[/module]</textarea></li>');
		}
		unset($row);
	?>
	</ul>
</div>
</div>

</td>
    </tr>
</table>
<script>
$("#content_<?php echo($cid) ?>").wysiwyg({css: '/admin/resources/client/bundle.css',initialContent:'<?php echo($content['content']); ?>'});
setTimeout(function(){$("#iist1").click();},100);

</script>